<?php


abstract class BaseTaxiOrder extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $created_at;


	
	protected $date;


	
	protected $time;


	
	protected $name;


	
	protected $contact_number;


	
	protected $pickup_address;


	
	protected $destination_address;


	
	protected $number_of_passengers = 1;


	
	protected $number_of_luggage = 0;


	
	protected $vehicle_type;


	
	protected $comment;


	
	protected $cost;


	
	protected $driver_id;

	
	protected $aTaxiDriver;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getDate($format = 'Y-m-d')
	{

		if ($this->date === null || $this->date === '') {
			return null;
		} elseif (!is_int($this->date)) {
						$ts = strtotime($this->date);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [date] as date/time value: " . var_export($this->date, true));
			}
		} else {
			$ts = $this->date;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getTime($format = 'H:i:s')
	{

		if ($this->time === null || $this->time === '') {
			return null;
		} elseif (!is_int($this->time)) {
						$ts = strtotime($this->time);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [time] as date/time value: " . var_export($this->time, true));
			}
		} else {
			$ts = $this->time;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getName()
	{

		return $this->name;
	}

	
	public function getContactNumber()
	{

		return $this->contact_number;
	}

	
	public function getPickupAddress()
	{

		return $this->pickup_address;
	}

	
	public function getDestinationAddress()
	{

		return $this->destination_address;
	}

	
	public function getNumberOfPassengers()
	{

		return $this->number_of_passengers;
	}

	
	public function getNumberOfLuggage()
	{

		return $this->number_of_luggage;
	}

	
	public function getVehicleType()
	{

		return $this->vehicle_type;
	}

	
	public function getComment()
	{

		return $this->comment;
	}

	
	public function getCost()
	{

		return $this->cost;
	}

	
	public function getDriverId()
	{

		return $this->driver_id;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::ID;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = TaxiOrderPeer::CREATED_AT;
		}

	} 
	
	public function setDate($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [date] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->date !== $ts) {
			$this->date = $ts;
			$this->modifiedColumns[] = TaxiOrderPeer::DATE;
		}

	} 
	
	public function setTime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [time] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->time !== $ts) {
			$this->time = $ts;
			$this->modifiedColumns[] = TaxiOrderPeer::TIME;
		}

	} 
	
	public function setName($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::NAME;
		}

	} 
	
	public function setContactNumber($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->contact_number !== $v) {
			$this->contact_number = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::CONTACT_NUMBER;
		}

	} 
	
	public function setPickupAddress($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->pickup_address !== $v) {
			$this->pickup_address = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::PICKUP_ADDRESS;
		}

	} 
	
	public function setDestinationAddress($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->destination_address !== $v) {
			$this->destination_address = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::DESTINATION_ADDRESS;
		}

	} 
	
	public function setNumberOfPassengers($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->number_of_passengers !== $v || $v === 1) {
			$this->number_of_passengers = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::NUMBER_OF_PASSENGERS;
		}

	} 
	
	public function setNumberOfLuggage($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->number_of_luggage !== $v || $v === 0) {
			$this->number_of_luggage = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::NUMBER_OF_LUGGAGE;
		}

	} 
	
	public function setVehicleType($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->vehicle_type !== $v) {
			$this->vehicle_type = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::VEHICLE_TYPE;
		}

	} 
	
	public function setComment($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->comment !== $v) {
			$this->comment = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::COMMENT;
		}

	} 
	
	public function setCost($v)
	{

		if ($this->cost !== $v) {
			$this->cost = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::COST;
		}

	} 
	
	public function setDriverId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->driver_id !== $v) {
			$this->driver_id = $v;
			$this->modifiedColumns[] = TaxiOrderPeer::DRIVER_ID;
		}

		if ($this->aTaxiDriver !== null && $this->aTaxiDriver->getId() !== $v) {
			$this->aTaxiDriver = null;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->created_at = $rs->getTimestamp($startcol + 1, null);

			$this->date = $rs->getDate($startcol + 2, null);

			$this->time = $rs->getTime($startcol + 3, null);

			$this->name = $rs->getString($startcol + 4);

			$this->contact_number = $rs->getString($startcol + 5);

			$this->pickup_address = $rs->getString($startcol + 6);

			$this->destination_address = $rs->getString($startcol + 7);

			$this->number_of_passengers = $rs->getInt($startcol + 8);

			$this->number_of_luggage = $rs->getInt($startcol + 9);

			$this->vehicle_type = $rs->getString($startcol + 10);

			$this->comment = $rs->getString($startcol + 11);

			$this->cost = $rs->getFloat($startcol + 12);

			$this->driver_id = $rs->getInt($startcol + 13);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 14; 
		} catch (Exception $e) {
			throw new PropelException("Error populating TaxiOrder object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TaxiOrderPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TaxiOrderPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isNew() && !$this->isColumnModified(TaxiOrderPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TaxiOrderPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aTaxiDriver !== null) {
				if ($this->aTaxiDriver->isModified()) {
					$affectedRows += $this->aTaxiDriver->save($con);
				}
				$this->setTaxiDriver($this->aTaxiDriver);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TaxiOrderPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TaxiOrderPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aTaxiDriver !== null) {
				if (!$this->aTaxiDriver->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTaxiDriver->getValidationFailures());
				}
			}


			if (($retval = TaxiOrderPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TaxiOrderPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getCreatedAt();
				break;
			case 2:
				return $this->getDate();
				break;
			case 3:
				return $this->getTime();
				break;
			case 4:
				return $this->getName();
				break;
			case 5:
				return $this->getContactNumber();
				break;
			case 6:
				return $this->getPickupAddress();
				break;
			case 7:
				return $this->getDestinationAddress();
				break;
			case 8:
				return $this->getNumberOfPassengers();
				break;
			case 9:
				return $this->getNumberOfLuggage();
				break;
			case 10:
				return $this->getVehicleType();
				break;
			case 11:
				return $this->getComment();
				break;
			case 12:
				return $this->getCost();
				break;
			case 13:
				return $this->getDriverId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TaxiOrderPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getCreatedAt(),
			$keys[2] => $this->getDate(),
			$keys[3] => $this->getTime(),
			$keys[4] => $this->getName(),
			$keys[5] => $this->getContactNumber(),
			$keys[6] => $this->getPickupAddress(),
			$keys[7] => $this->getDestinationAddress(),
			$keys[8] => $this->getNumberOfPassengers(),
			$keys[9] => $this->getNumberOfLuggage(),
			$keys[10] => $this->getVehicleType(),
			$keys[11] => $this->getComment(),
			$keys[12] => $this->getCost(),
			$keys[13] => $this->getDriverId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TaxiOrderPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setCreatedAt($value);
				break;
			case 2:
				$this->setDate($value);
				break;
			case 3:
				$this->setTime($value);
				break;
			case 4:
				$this->setName($value);
				break;
			case 5:
				$this->setContactNumber($value);
				break;
			case 6:
				$this->setPickupAddress($value);
				break;
			case 7:
				$this->setDestinationAddress($value);
				break;
			case 8:
				$this->setNumberOfPassengers($value);
				break;
			case 9:
				$this->setNumberOfLuggage($value);
				break;
			case 10:
				$this->setVehicleType($value);
				break;
			case 11:
				$this->setComment($value);
				break;
			case 12:
				$this->setCost($value);
				break;
			case 13:
				$this->setDriverId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TaxiOrderPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCreatedAt($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setDate($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setTime($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setName($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setContactNumber($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setPickupAddress($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setDestinationAddress($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setNumberOfPassengers($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setNumberOfLuggage($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setVehicleType($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setComment($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setCost($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setDriverId($arr[$keys[13]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TaxiOrderPeer::DATABASE_NAME);

		if ($this->isColumnModified(TaxiOrderPeer::ID)) $criteria->add(TaxiOrderPeer::ID, $this->id);
		if ($this->isColumnModified(TaxiOrderPeer::CREATED_AT)) $criteria->add(TaxiOrderPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(TaxiOrderPeer::DATE)) $criteria->add(TaxiOrderPeer::DATE, $this->date);
		if ($this->isColumnModified(TaxiOrderPeer::TIME)) $criteria->add(TaxiOrderPeer::TIME, $this->time);
		if ($this->isColumnModified(TaxiOrderPeer::NAME)) $criteria->add(TaxiOrderPeer::NAME, $this->name);
		if ($this->isColumnModified(TaxiOrderPeer::CONTACT_NUMBER)) $criteria->add(TaxiOrderPeer::CONTACT_NUMBER, $this->contact_number);
		if ($this->isColumnModified(TaxiOrderPeer::PICKUP_ADDRESS)) $criteria->add(TaxiOrderPeer::PICKUP_ADDRESS, $this->pickup_address);
		if ($this->isColumnModified(TaxiOrderPeer::DESTINATION_ADDRESS)) $criteria->add(TaxiOrderPeer::DESTINATION_ADDRESS, $this->destination_address);
		if ($this->isColumnModified(TaxiOrderPeer::NUMBER_OF_PASSENGERS)) $criteria->add(TaxiOrderPeer::NUMBER_OF_PASSENGERS, $this->number_of_passengers);
		if ($this->isColumnModified(TaxiOrderPeer::NUMBER_OF_LUGGAGE)) $criteria->add(TaxiOrderPeer::NUMBER_OF_LUGGAGE, $this->number_of_luggage);
		if ($this->isColumnModified(TaxiOrderPeer::VEHICLE_TYPE)) $criteria->add(TaxiOrderPeer::VEHICLE_TYPE, $this->vehicle_type);
		if ($this->isColumnModified(TaxiOrderPeer::COMMENT)) $criteria->add(TaxiOrderPeer::COMMENT, $this->comment);
		if ($this->isColumnModified(TaxiOrderPeer::COST)) $criteria->add(TaxiOrderPeer::COST, $this->cost);
		if ($this->isColumnModified(TaxiOrderPeer::DRIVER_ID)) $criteria->add(TaxiOrderPeer::DRIVER_ID, $this->driver_id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TaxiOrderPeer::DATABASE_NAME);

		$criteria->add(TaxiOrderPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCreatedAt($this->created_at);

		$copyObj->setDate($this->date);

		$copyObj->setTime($this->time);

		$copyObj->setName($this->name);

		$copyObj->setContactNumber($this->contact_number);

		$copyObj->setPickupAddress($this->pickup_address);

		$copyObj->setDestinationAddress($this->destination_address);

		$copyObj->setNumberOfPassengers($this->number_of_passengers);

		$copyObj->setNumberOfLuggage($this->number_of_luggage);

		$copyObj->setVehicleType($this->vehicle_type);

		$copyObj->setComment($this->comment);

		$copyObj->setCost($this->cost);

		$copyObj->setDriverId($this->driver_id);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TaxiOrderPeer();
		}
		return self::$peer;
	}

	
	public function setTaxiDriver($v)
	{


		if ($v === null) {
			$this->setDriverId(NULL);
		} else {
			$this->setDriverId($v->getId());
		}


		$this->aTaxiDriver = $v;
	}


	
	public function getTaxiDriver($con = null)
	{
		if ($this->aTaxiDriver === null && ($this->driver_id !== null)) {
						$this->aTaxiDriver = TaxiDriverPeer::retrieveByPK($this->driver_id, $con);

			
		}
		return $this->aTaxiDriver;
	}

} 